#! /usr/bin/python
# -*- coding: cp1250 -*-
#sys.path.append(r'C:\AFT\.pylib')

import string, sys
import pepe.p_txt.bigtxt as bt
import pepe.p_txt.findcdelimiter as fcd

def main(ifile):
    '''
    Purpose:    Strips blank spaces around delimiters of csv files.
    Syntax:     csv_strip <inp_file>
    Example:    csv_strip test.csv
    '''
    of = open(ifile+'_stripped', 'w')

    lino = 0
    cd = ""
    for line in bt.lines(ifile):
        # find what column delimiter is used 
        if cd == "": cd = fcd.fcd(line)

        lino += 1
        cols = string.split(line, cd)
        bare_cols = [string.strip(c) for c in cols]
        of.write(string.join(bare_cols, cd)+'\n')
    of.close()

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print main.__doc__
    else:
        main(sys.argv[1])

